package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.MedicalRecord;
import com.noahplat.person.service.MedicalRecordService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: MedicalRecordController
 * @Description: 就诊记录对外接口
 * @Author 李景星
 * @Date 2021/3/6
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/medicalRecord")
@Validated
public class MedicalRecordController {

    @Autowired
    private MedicalRecordService medicalRecordService;

    /**
     * 增加就诊记录
     * @param medicalRecord
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:MedicalRecordController:addMedicalRecord')")
    @PostMapping("/addMedicalRecord")
    public Result addMedicalRecord(@Validated @RequestBody MedicalRecord medicalRecord){
        return medicalRecordService.addMedicalRecord(medicalRecord);
    }

    /**
     * 更新就诊记录/删除就诊记录（删除标识更新为Y）
     * @param medicalRecord
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:MedicalRecordController:updateMedicalRecord')")
    @PutMapping("/updateMedicalRecord")
    public Result updateMedicalRecord(@Validated @RequestBody MedicalRecord medicalRecord){
        return medicalRecordService.updateMedicalRecord(medicalRecord);
    }

    /**
     * 查询就诊记录详情
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:MedicalRecordController:getMedicalRecordInfo')")
    @GetMapping("/getMedicalRecordInfo")
    public Result getMedicalRecordInfo(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "ID不合法") Long id){
        return medicalRecordService.getMedicalRecordInfo(id);
    }
}
